//
//  AITree.cpp
//  KPGranny2
//
//  Created by bianchx on 15/9/15.
//
//

#include "AiTreeTest.h"

#include <iostream>
#include <sstream>

using namespace std;

int main()
{
    // AiNodeType types[] = 
    // {
    //     ANT_RELEASE_SKILL,
    //     ANT_PICKING_UP_COINS,
    //     ANT_GOTO_OWNER_SIDE,
    //     ANT_FIND_SOMETHING,
    // }; 

    AINodeDescribe des[] = {
        AINodeDescribe(1, 0, ANBT_SELECT, "根节点"),

        AINodeDescribe(2, 1, ANBT_SEQUENCE, "是否拾取金币的判定节点"),
        AINodeDescribe(5, 2, ANT_RELEASE_SKILL, "附近是否存在金币"),
        AINodeDescribe(6, 2, ANT_PICKING_UP_COINS, "捡取金币节点"),

        AINodeDescribe(3, 1, ANBT_SEQUENCE, "是否回到主人身边的判定节点"),
        AINodeDescribe(7, 3, ANT_RELEASE_SKILL, "是不是很长时间没有见到金币了"),
        AINodeDescribe(8, 3, ANT_PICKING_UP_COINS, "是不是很长时间没有回到主人身边了"),
        AINodeDescribe(9, 3, ANT_PICKING_UP_COINS, "回到主人身边的执行节点"),

        AINodeDescribe(4, 1, ANT_PICKING_UP_COINS, "没事随便逛逛吧"),
    };

    int desCount = sizeof(des) / sizeof(AINodeDescribe);

    vector<AINodeDescribe> des_vtr;
    for (int i = 0; i < desCount; ++i)
    {
        des_vtr.push_back(des[i]);
    }

    AINodeBase * rootNode = AINodeHelper::sharedHelper()->CreateNodeTree(des_vtr);

    cout << "\n状态结构组织图 \n" << endl;
    AINodeHelper::sharedHelper()->printAITree(rootNode);

    cout << "\n状态结构组织图 \n" << endl;

    for (int i = 0; i < 10; ++i)
    {
        cout << "调用树开始" << endl;

        rootNode->invoke(0, true);

        cout << "调用树结束" << endl;
    }

    rootNode->destroy();

    return 0;
}

// AINodeRegister<AINodeReleaseSkill> AINodeReleaseSkill::reg(ANT_RELEASE_SKILL);

AINodeRegister<AINodeReleaseSkill> AINodeReleaseSkill::reg(ANT_RELEASE_SKILL, "AINodeReleaseSkill");
bool AINodeReleaseSkill::invoke(int level, bool isLog)
{
    return rand() % 100 > 20;
}

AINodeRegister<AINodePickingUpCoins> AINodePickingUpCoins::reg(ANT_PICKING_UP_COINS, "AINodePickingUpCoins");
bool AINodePickingUpCoins::invoke(int level, bool isLog)
{   
    return rand() % 100 > 20;
}

AINodeRegister<AINodeGotoOwnerSide> AINodeGotoOwnerSide::reg(ANT_GOTO_OWNER_SIDE, "AINodeGotoOwnerSide");
bool AINodeGotoOwnerSide::invoke(int level, bool isLog)
{
    return rand() % 100 > 20;
}

AINodeRegister<AINodeFindSomething> AINodeFindSomething::reg(ANT_FIND_SOMETHING, "AINodeFindSomething");
bool AINodeFindSomething::invoke(int level, bool isLog)
{
    return rand() % 100 > 20;
}